<?php 
include_once("config.php");
$valid_users = array_keys($valid_passwords);
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
$validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
if (!$validated) {
	header('WWW-Authenticate: Basic realm="My Realm"');
	header('HTTP/1.0 401 Unauthorized');
	die ("Not authorized");
}

$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8mb4")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}
?><!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>周生生</title>
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<link rel="shortcut icon" href="http://wechat.levi.com.cn/attachment/images/global/wechat.jpg" />
	<link href="./resource/css/bootstrap.min.css" rel="stylesheet">
	<link href="./resource/css/font-awesome.min.css" rel="stylesheet">
	<link href="./resource/css/common.css" rel="stylesheet">
	<script>var require = { urlArgs: 'v=2015080716' };</script>
	<script src="./resource/js/require.js"></script>
	<script src="./resource/js/app/config.js"></script>
	<script src="./resource/js/lib/jquery-1.11.1.min.js"></script>
	<!--[if lt IE 9]>
		<script src="./resource/js/html5shiv.min.js"></script>
		<script src="./resource/js/respond.min.js"></script>
	<![endif]-->
	<script type="text/javascript">
	if(navigator.appName == 'Microsoft Internet Explorer'){
		if(navigator.userAgent.indexOf("MSIE 5.0")>0 || navigator.userAgent.indexOf("MSIE 6.0")>0 || navigator.userAgent.indexOf("MSIE 7.0")>0) {
			alert('您使用的 IE 浏览器版本过低, 推荐使用 Chrome 浏览器或 IE8 及以上版本浏览器.');
		}
	}

	</script>
</head>
<body>	<div class="navbar navbar-static-top" role="navigation">
	    <br />
		<div class="container-fluid"><img style="position:relative;margin:0px auto;display:block;" src="logo.png"></div>
	</div>
	<div class="container-fluid">
				<div class="row">
						<div class="col-xs-12 col-sm-3 col-lg-2 big-menu">
						<div class="panel panel-default">
						<div class="panel-heading">
							<h4 class="panel-title">基本功能</h4>
							<a class="panel-collapse" data-toggle="collapse" href="#frame-0">
								<i class="fa fa-chevron-circle-down"></i>
							</a>
						</div>
							<?php include_once 'menua.php'; ?>
					</div>
							
									</div>
				<div class="col-xs-12 col-sm-9 col-lg-10">
									

<div class="clearfix ng-cloak" ng-controller="replyForm">
    <span style="color:red;"><?php 
    if (isset($_POST['submit'])){
    	$query=$mysqli->query("select type,num from hshu limit 0, 100");
    	$data=array();
    	while ($list=$query->fetch_array()){
    		$data[$list['type']] =$list['num'];
    	}
    	$ja=$data['ja'];
    	$jb=$data['jb'];
    	$jc=$data['jc'];
    	$total=$ja+$jb+$jc;
    	if ($total<2){
    		$total=2;
    	}
    	$jData=range(1, $total);
    	shuffle($jData);
    	$mysqli->query("truncate chi");
    	$mysqli->query("truncate log");
    	for ($i=1;$i<=$ja;$i++){
    		$_data= array_pop($jData);
    		$mysqli->query("INSERT into chi(type,uid,status) values('1',".$_data.", 'work')");
    	}
    
    	for ($i=1;$i<=$jb;$i++){
    		$_data= array_pop($jData);
    		$mysqli->query("INSERT into chi(type,uid,status) values('2',".$_data.", 'work')");
    	}
    
    	for ($i=1;$i<=$jc;$i++){
    		$_data= array_pop($jData);
    		$mysqli->query("INSERT into chi(type,uid,status) values('3',".$_data.", 'work')");
    	}
    	echo '更新成功';
    }
    ?></span>
	<form id="reply-form" class="form-horizontal form" action="s.php?act=5" method="post" enctype="multipart/form-data">
		<div class="form-group">
			<div class="col-sm-12">
				<input name="submit" type="submit" value="确认更新数据" class="btn btn-primary col-lg-1" />
				
			</div>
		</div>
	</form>
	<span style="font-size:12px;color:red;"> 
当更新了奖品数量,请点击上方按钮，重新初始化数据。 </span>
</div>
			</div>
		</div>
	</div>




	<script>
	require(['angular.sanitize', 'bootstrap', 'underscore', 'util'], function(angular, $, _, util){
		angular.module('app', ['ngSanitize']).controller('replyForm', function($scope, $http){});
		angular.bootstrap(document, ['app']);
	});
	require(['bootstrap']);
	</script>
	
</body>
</html>
